package com.beiing.tianshuai.tianshuai.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.app.HttpRequestConstant;
import com.beiing.tianshuai.tianshuai.base.BaseRecyclerViewAdapter;
import com.beiing.tianshuai.tianshuai.entity.PersonalDynamicBean;
import com.beiing.tianshuai.tianshuai.entity.PersonalInfoBean;
import com.beiing.tianshuai.tianshuai.util.DateUtil;
import com.beiing.tianshuai.tianshuai.util.SpanStringUtils;
import com.beiing.tianshuai.tianshuai.widget.CircleImageView;
import com.beiing.tianshuai.tianshuai.widget.FooterView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bingoogolapple.bgabanner.BGAOnNoDoubleClickListener;

/**
 * Created by Jinni on 2017/7/20 0020.
 */

public class PersonalDynamicAdapter extends BaseRecyclerViewAdapter<PersonalDynamicBean.DataBean.NumberBean> {

    private static final int DYNAMIC_NORMAL = 0;                 // 普通动态
    private static final int DYNAMIC_FROM_OTHER = 1;             // 转发动态
    private static final int ITEM_VIEW_TYPE_FOOTER = 2;          // 转发动态
    private static final int ITEM_VIEW_TYPE_HEADER = 3;          // 个人资料头部

    private PersonalInfoBean mUserInfoBean;
    private OnItemClickListener mListener;
    private OnCenterMenuClickListener mOnCenterMenuClickListener;
    private OnAvatarClickListener mOnAvatarClickListener;
    private OnFansClickListener mOnFansClickListener;
    private Context mContext;
    private int mFooterStatus;

    public PersonalDynamicAdapter(Context context, PersonalInfoBean userInfoBean) {
        this.mContext = context;
        this.mUserInfoBean = userInfoBean;
    }

    public void setFooterStatus(int footerStatus) {
        mFooterStatus = footerStatus;
    }

    public void setListener(OnItemClickListener listener) {
        mListener = listener;
    }

    public void setOnCenterMenuClickListener(OnCenterMenuClickListener onCenterMenuClickListener) {
        mOnCenterMenuClickListener = onCenterMenuClickListener;
    }

    public void setOnAvatarClickListener(OnAvatarClickListener onAvatarClickListener) {
        mOnAvatarClickListener = onAvatarClickListener;
    }

    public void setOnFansClickListener(OnFansClickListener listener){
        this.mOnFansClickListener = listener;
    }

    public PersonalInfoBean getUserInfoBean() {
        return mUserInfoBean;
    }

    @Override
    public int getItemViewType(int position) {
        int result = 0;
        if (position == mList.size() + 1) {
            result = ITEM_VIEW_TYPE_FOOTER;
        } else if (position == 0) {
            result = ITEM_VIEW_TYPE_HEADER;
        } else {
            switch (mList.get(position - 1).getTableType()) {
                case "0":
                    result = DYNAMIC_NORMAL;
                    break;
                case "1":
                    result = DYNAMIC_FROM_OTHER;
                    break;
                    default:break;
            }

        }
        return result;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder holder = null;
        switch (viewType) {
            case ITEM_VIEW_TYPE_HEADER:
                holder = new HeaderHolder(View.inflate(mContext, R.layout.item_personal_index_header, null));
                break;
            case DYNAMIC_FROM_OTHER:
                holder = new NormalHolder(View.inflate(mContext, R.layout.item_dynamic_normal, null));
                break;
            case DYNAMIC_NORMAL:
                holder = new OtherHolder(View.inflate(mContext, R.layout.item_dynamic_from_other, null));
                break;
            case ITEM_VIEW_TYPE_FOOTER:
                if (mFooterView == null) {
                    mFooterView = new FooterView(mContext);
                    mFooterView.setLayoutParams(
                            new LinearLayout.LayoutParams(
                                    ViewGroup.LayoutParams.MATCH_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT
                            )
                    );
                }
                return new FooterViewHolder(mFooterView);
            default:break;

        }
        return holder;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof NormalHolder) {
            holder.setIsRecyclable(true);
            PersonalDynamicBean.DataBean.NumberBean bean = mList.get(position - 1);
            RequestOptions requestOptions = new RequestOptions()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .override(350, 350);
            Glide.with(mContext.getApplicationContext())
                    .load(TextUtils.isEmpty(
                            bean.getPhoto()) ?
                            R.mipmap.default_avatar :
                            HttpRequestConstant.USER_PIC_HEAD + bean.getPhoto())
                    .apply(requestOptions)
                    .into(((NormalHolder) holder).mUserAvatar);
            ((NormalHolder) holder).mUserName.setText(bean.getName());
            ((NormalHolder) holder).mContactName.setText(bean.getUnit());
            if (bean.getContent().isEmpty()) {
                ((NormalHolder) holder).mDynamicContent.setVisibility(View.GONE);
            } else {
                ((NormalHolder) holder).mDynamicContent.setVisibility(View.VISIBLE);
                try {
                    String contentDecode = URLDecoder.decode(bean.getContent(), "UTF-8");
                    ((NormalHolder) holder).mDynamicContent.setText(SpanStringUtils.getEmotionContent(mContext, ((NormalHolder) holder).mDynamicContent, contentDecode));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            checkTextViewLinesCount(((NormalHolder) holder).mDynamicContent, ((NormalHolder) holder).mDynamicViewAll);
            List<PersonalDynamicBean.DataBean.NumberBean.PicBean> pic = bean.getPic();
            if (pic.size() > 0) {
                ((NormalHolder) holder).mNineGridView.setVisibility(View.VISIBLE);
                ArrayList<ImageInfo> imageInfos = new ArrayList<>();
                for (PersonalDynamicBean.DataBean.NumberBean.PicBean picBean : pic) {
                    String url = HttpRequestConstant.DYNAMIC_PIC_HEAD + picBean.getPicname();
//                    String thumbUrl = HttpRequestConstant.DYNAMIC_PIC_THUMBNAIL + picBean.getPicname();
                    ImageInfo imageInfo = new ImageInfo();
                    imageInfo.setThumbnailUrl(url);
                    imageInfo.setBigImageUrl(url);
                    imageInfo.setImageViewHeight(Integer.parseInt(picBean.getHeight()));
                    imageInfo.setImageViewWidth(Integer.parseInt(picBean.getWidth()));
                    imageInfo.setImageHeight(Integer.parseInt(picBean.getHeight()));
                    imageInfo.setImageWidth(Integer.parseInt(picBean.getWidth()));
                    imageInfos.add(imageInfo);
                }
                ((NormalHolder) holder).mNineGridView.setAdapter(new NineGridViewClickAdapter(mContext, imageInfos));
                if (pic.size() == 1) {
                    ((NormalHolder) holder).mNineGridView.setSingleImageSize(600);
                }
            } else {
                ((NormalHolder) holder).mNineGridView.setVisibility(View.GONE);
            }
            ((NormalHolder) holder).mNumComment.setText(bean.getComment());
            ((NormalHolder) holder).mNumReprint.setText(bean.getRelay());
            ((NormalHolder) holder).mNumLike.setText(bean.getThing());
            boolean isLiked = bean.getIsThing() == 1;
            Drawable drawableLike;
            if (isLiked) {
                drawableLike = mContext.getResources().getDrawable(R.drawable.ic_dynamic_praise_red);
            } else {
                drawableLike = mContext.getResources().getDrawable(R.drawable.ic_dynamic_praise);
            }
            drawableLike.setBounds(0, 0, drawableLike.getMinimumWidth(), drawableLike.getMinimumHeight());
            ((NormalHolder) holder).mNumLike.setCompoundDrawables(drawableLike, null, null, null);
            String uid = bean.getUid();
            if (com.beiing.tianshuai.tianshuai.entity.UserInfoBean.getUid(mContext).equals(uid)) {
                ((NormalHolder) holder).mDynamicMenu.setVisibility(View.VISIBLE);
            } else {
                ((NormalHolder) holder).mDynamicMenu.setVisibility(View.GONE);
            }
            setOnItemClickListener(holder, bean);
            ((NormalHolder) holder).mDynamicTime.setText(getTime(bean.getCreateTime()));
            ((NormalHolder) holder).commentRecyclerView.setVisibility(View.GONE);
        } else if (holder instanceof OtherHolder) {
            holder.setIsRecyclable(true);
            PersonalDynamicBean.DataBean.NumberBean bean = mList.get(position - 1);
            RequestOptions requestOptions = new RequestOptions()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .override(350, 350);
            Glide.with(mContext.getApplicationContext())
                    .load(TextUtils.isEmpty(
                            bean.getRPhoto()) ?
                            R.mipmap.default_avatar :
                            HttpRequestConstant.USER_PIC_HEAD + bean.getRPhoto())
                    .apply(requestOptions)
                    .into(((OtherHolder) holder).mUserAvatar);
            ((OtherHolder) holder).mUserName.setText(bean.getRName());
            ((OtherHolder) holder).mDynamicOriginalUsername.setText(MessageFormat.format("@{0}", bean.getName()));
            ((OtherHolder) holder).mContactName.setText(bean.getRunit());
            if (bean.getContent() == null || bean.getContent().equals("")) {
                ((OtherHolder) holder).mDynamicOriginalContent.setVisibility(View.GONE);
            } else {
                ((OtherHolder) holder).mDynamicOriginalContent.setVisibility(View.VISIBLE);
                try {
                    String contentDecode = URLDecoder.decode(bean.getContent(), "UTF-8");
                    ((OtherHolder) holder).mDynamicOriginalContent.setText(SpanStringUtils.getEmotionContent(mContext, ((OtherHolder) holder).mDynamicOriginalContent, contentDecode));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            checkTextViewLinesCount(
                    ((OtherHolder) holder).mDynamicOriginalContent,
                    ((OtherHolder) holder).mTvOriginalViewAll);

            if (bean.getRContent().isEmpty()) {
                ((OtherHolder) holder).mDynamicReprintContent.setVisibility(View.GONE);
            } else {
                ((OtherHolder) holder).mDynamicReprintContent.setVisibility(View.VISIBLE);
                try {
                    String rContentDecode = URLDecoder.decode(bean.getRContent(), "UTF-8");
                    ((OtherHolder) holder).mDynamicReprintContent.setText(SpanStringUtils.getEmotionContent(mContext, ((OtherHolder) holder).mDynamicReprintContent,rContentDecode));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            checkTextViewLinesCount(
                    ((OtherHolder) holder).mDynamicReprintContent,
                    ((OtherHolder) holder).mTvReprintViewAll);

            List<PersonalDynamicBean.DataBean.NumberBean.PicBean> pic = bean.getPic();
            if (pic != null && pic.size() > 0) {
                ((OtherHolder) holder).mNineGridView.setVisibility(View.VISIBLE);
                ArrayList<ImageInfo> imageInfos = new ArrayList<>();
                for (PersonalDynamicBean.DataBean.NumberBean.PicBean picBean : pic) {
                    String url = HttpRequestConstant.DYNAMIC_PIC_HEAD + picBean.getPicname();
//                    String thumbUrl = HttpRequestConstant.DYNAMIC_PIC_THUMBNAIL + picBean.getPicname();
                    ImageInfo imageInfo = new ImageInfo();
                    imageInfo.setThumbnailUrl(url);
                    imageInfo.setBigImageUrl(url);
                    imageInfo.setImageViewHeight(Integer.parseInt(picBean.getHeight()));
                    imageInfo.setImageViewWidth(Integer.parseInt(picBean.getWidth()));
                    imageInfo.setImageHeight(Integer.parseInt(picBean.getHeight()));
                    imageInfo.setImageWidth(Integer.parseInt(picBean.getWidth()));
                    imageInfos.add(imageInfo);
                }
                ((OtherHolder) holder).mNineGridView.setAdapter(new NineGridViewClickAdapter(mContext, imageInfos));
                if (pic.size() == 1) {
                    ((OtherHolder) holder).mNineGridView.setSingleImageSize(200);
                }
            } else {
                ((OtherHolder) holder).mNineGridView.setVisibility(View.GONE);
            }
            ((OtherHolder) holder).mNumComment.setText(bean.getComment());
            ((OtherHolder) holder).mNumReprint.setText(bean.getRelay());
            ((OtherHolder) holder).mNumLike.setText(bean.getThing());
            boolean isLiked = bean.getIsThing() == 1;
            Drawable drawableLike;
            if (isLiked) {
                drawableLike = mContext.getResources().getDrawable(R.drawable.ic_dynamic_praise_red);
            } else {
                drawableLike = mContext.getResources().getDrawable(R.drawable.ic_dynamic_praise);
            }
            drawableLike.setBounds(0, 0, drawableLike.getMinimumWidth(), drawableLike.getMinimumHeight());
            ((OtherHolder) holder).mNumLike.setCompoundDrawables(drawableLike, null, null, null);
            String uid = bean.getFormUid();
            if (com.beiing.tianshuai.tianshuai.entity.UserInfoBean.getUid(mContext).equals(uid)) {
                ((OtherHolder) holder).mDynamicMenu.setVisibility(View.VISIBLE);
            } else {
                ((OtherHolder) holder).mDynamicMenu.setVisibility(View.GONE);
            }
            setOnItemClickListener(holder, bean);
            ((OtherHolder) holder).mDynamicTime.setText(getTime(bean.getRCreateTime()));
            ((OtherHolder) holder).commentRecyclerView.setVisibility(View.GONE);
        } else if (holder instanceof FooterViewHolder) {
            if ((position - 1) == mList.size() && mFooterView.getStatus() != FooterView.NO_MORE) {
                setFooterViewStatus(mFooterStatus);
            }
        } else if (holder instanceof HeaderHolder) {
            ((HeaderHolder) holder).setData();
            ((HeaderHolder) holder).setListener();
        }
    }

    private void setOnItemClickListener(final RecyclerView.ViewHolder holder, final PersonalDynamicBean.DataBean.NumberBean bean) {
        if (holder instanceof NormalHolder) {
            // 评论
            ((NormalHolder) holder).mNumComment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 点赞
            ((NormalHolder) holder).mNumLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        int position = holder.getAdapterPosition();
                        PersonalDynamicBean.DataBean.NumberBean bean = mList.get(position - 1);
                        boolean isLiked = bean.getIsThing() == 1;
                        String aid = bean.getId();
                        mListener.OnLikeClickListener(position, isLiked, v, aid, ((NormalHolder) holder).mTvAddOne);
                        if (isLiked) {
                            bean.setIsThing(0);
                        } else {
                            bean.setIsThing(1);
                        }
                    }
                }
            });

            // 转发
            ((NormalHolder) holder).mNumReprint.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnReprintClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 菜单
            ((NormalHolder) holder).mDynamicMenu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnMenuClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 条目
            ((NormalHolder) holder).mItem.setOnClickListener(new BGAOnNoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 查看全部
            ((NormalHolder) holder).mDynamicContent.setOnClickListener(new BGAOnNoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });
        } else if (holder instanceof OtherHolder) {
            // 评论
            ((OtherHolder) holder).mNumComment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 点赞
            ((OtherHolder) holder).mNumLike.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        int position = holder.getAdapterPosition();
                        PersonalDynamicBean.DataBean.NumberBean bean = mList.get(position);
                        boolean isLiked = bean.getIsThing() == 1;
                        String aid = bean.getId();
                        mListener.OnLikeClickListener(position, isLiked, v, aid, ((OtherHolder) holder).mTvAddOne);
                        if (isLiked) {
                            bean.setIsThing(0);
                        } else {
                            bean.setIsThing(1);
                        }
                    }
                }
            });

            // 转发
            ((OtherHolder) holder).mNumReprint.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnReprintClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 菜单
            ((OtherHolder) holder).mDynamicMenu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnMenuClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 条目
            ((OtherHolder) holder).mItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 源作者
            ((OtherHolder) holder).mDynamicOriginalUsername.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.OnRNameClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 查看全部
            ((OtherHolder) holder).mTvOriginalViewAll.setOnClickListener(new BGAOnNoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });

            // 查看全部
            ((OtherHolder) holder).mTvReprintViewAll.setOnClickListener(new BGAOnNoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (mListener != null) {
                        mListener.OnCommentClickListener(holder.getAdapterPosition(), bean);
                    }
                }
            });
        }
    }


    private void checkTextViewLinesCount(final TextView content, final TextView viewAll) {
        content.post(new Runnable() {
            @Override
            public void run() {
                int lineCount = content.getLineCount();
                if (lineCount >= 5) {
                    viewAll.setVisibility(View.VISIBLE);
                } else {
                    viewAll.setVisibility(View.GONE);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        if (mList != null && !mList.isEmpty()) {
            return mList.size() + 2;
        } else {
            return 1;
        }
    }

    class HeaderHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.civ_user_avatar)
        QMUIRadiusImageView mCivUserAvatar;
        @BindView(R.id.tv_user_university)
        TextView mTvUserUniversity;
        @BindView(R.id.tv_user_sign)
        TextView mTvUserSign;
        @BindView(R.id.tv_divider_followed)
        TextView mTvDividerFollowed;
        @BindView(R.id.tv_user_followed)
        TextView mTvUserFollowed;
        @BindView(R.id.tv_user_fans)
        TextView mTvUserFans;
        @BindView(R.id.rl_user_info_container)
        RelativeLayout mRlUserInfoContainer;
        @BindView(R.id.btn_follow)
        TextView mBtnFollow;
        @BindView(R.id.btn_add_friend)
        TextView mBtnAddFriend;
        @BindView(R.id.btn_chat)
        TextView mBtnChat;
        @BindView(R.id.tv_show_more_menu)
        TextView mTvShowMoreMenu;
        @BindView(R.id.ll_center_menu_container)
        LinearLayout mLlCenterMenuContainer;
        private boolean isFriend;
        private String mPhoto;
        private String uid;

        HeaderHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void setData() {

            if (mUserInfoBean.getData() == null || mUserInfoBean.getData().getUserinfor().isEmpty()) {
                return;
            }
            PersonalInfoBean.DataBean.UserInfoBean userInfoBean = mUserInfoBean.getData().getUserinfor().get(0);

            if (userInfoBean.getUid().equals(com.beiing.tianshuai.tianshuai.entity.UserInfoBean.getUid(mContext))){
                mLlCenterMenuContainer.setVisibility(View.GONE);
            } else {
                mLlCenterMenuContainer.setVisibility(View.VISIBLE);
            }

            // 学校
            String university = userInfoBean.getUnit();
            if (TextUtils.isEmpty(university)) {
                mTvUserUniversity.setVisibility(View.GONE);
            } else {
                mTvUserUniversity.setText(university);
            }

            // 签名
            String sign = userInfoBean.getSign();
            mTvUserSign.setText(TextUtils.isEmpty(sign) ? "这个人很懒什么都没说" : sign);

            // 头像
            mPhoto = userInfoBean.getPhoto();
            RequestOptions requestOptions = new RequestOptions()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .override(350, 350);
            Glide.with(mContext.getApplicationContext())
                    .load(TextUtils.isEmpty(
                            mPhoto) ?
                            R.mipmap.default_avatar :
                            HttpRequestConstant.USER_PIC_HEAD + mPhoto)
                    .apply(requestOptions)
                    .into(mCivUserAvatar);

            // 关注
            boolean isFollowed = TextUtils.equals(mUserInfoBean.getData().getIs_concern(), "1");
            mBtnFollow.setText(isFollowed ? "已关注" : "关注");
            mTvUserFollowed.setText(String.format(mContext.getResources().getString(R.string.zone_followed_num), mUserInfoBean.getData().getFrom().get(0).getFrom_count()));

            // 好友
            isFriend = TextUtils.equals(mUserInfoBean.getData().getIs_friends(), "1");
            mBtnAddFriend.setText(isFriend ? "已是好友" : "加好友");
            mBtnAddFriend.setClickable(!isFriend);
            mTvUserFans.setText(String.format(mContext.getResources().getString(R.string.zone_fans_num), mUserInfoBean.getData().getKeep().get(0).getKeep_count()));
            uid = mUserInfoBean.getData().getUserinfor().get(0).getUid();
        }

        public void setListener() {
            mBtnFollow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnCenterMenuClickListener != null) {
                        mOnCenterMenuClickListener.onFollowClick();
                    }
                }
            });

            mBtnAddFriend.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnCenterMenuClickListener != null) {
                        mOnCenterMenuClickListener.onAddFriendClick(isFriend);
                    }
                }
            });

            mBtnChat.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnCenterMenuClickListener != null) {
                        mOnCenterMenuClickListener.onChatClick(isFriend, mPhoto);
                    }
                }
            });

            mTvShowMoreMenu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnCenterMenuClickListener != null) {
                        mOnCenterMenuClickListener.onMoreClick(view);
                    }
                }
            });

            mCivUserAvatar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnAvatarClickListener != null) {
                        mOnAvatarClickListener.onAvatarClick(HttpRequestConstant.USER_PIC_HEAD + mPhoto);
                    }
                }
            });

            // 关注
            mTvUserFollowed.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnFansClickListener != null){
                        mOnFansClickListener.onFansClick(uid, 0);
                    }
                }
            });

            // 粉丝
            mTvUserFans.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnFansClickListener != null){
                        mOnFansClickListener.onFansClick(uid, 1);
                    }
                }
            });
        }
    }

    class NormalHolder extends RecyclerView.ViewHolder {

        private View mItem;

        @BindView(R.id.user_avatar)
        CircleImageView mUserAvatar;
        @BindView(R.id.user_name)
        TextView mUserName;
        @BindView(R.id.contact_name)
        TextView mContactName;
        @BindView(R.id.dynamic_content)
        TextView mDynamicContent;
        @BindView(R.id.nine_grid_view)
        NineGridView mNineGridView;
        @BindView(R.id.num_like)
        TextView mNumLike;
        @BindView(R.id.num_comment)
        TextView mNumComment;
        @BindView(R.id.num_reprint)
        TextView mNumReprint;
        @BindView(R.id.dynamic_publish_time)
        TextView mDynamicTime;
        @BindView(R.id.tv_add_one)
        TextView mTvAddOne;
        @BindView(R.id.dynamic_more)
        ImageView mDynamicMenu;
        @BindView(R.id.dynamic_view_all)
        TextView mDynamicViewAll;
        @BindView(R.id.normal_item_recycler)
        RecyclerView commentRecyclerView;

        NormalHolder(View view) {
            super(view);
            mItem = view;
            ButterKnife.bind(this, view);
        }
    }

    class OtherHolder extends RecyclerView.ViewHolder {

        private View mItem;

        @BindView(R.id.user_avatar)
        CircleImageView mUserAvatar;
        @BindView(R.id.user_name)
        TextView mUserName;
        @BindView(R.id.contact_name)
        TextView mContactName;
        @BindView(R.id.dynamic_reprint_content)
        TextView mDynamicReprintContent;
        @BindView(R.id.dynamic_original_username)
        TextView mDynamicOriginalUsername;
        @BindView(R.id.dynamic_original_content)
        TextView mDynamicOriginalContent;
        @BindView(R.id.nine_grid_view)
        NineGridView mNineGridView;
        @BindView(R.id.num_like)
        TextView mNumLike;
        @BindView(R.id.num_comment)
        TextView mNumComment;
        @BindView(R.id.num_reprint)
        TextView mNumReprint;
        @BindView(R.id.dynamic_more)
        ImageView mDynamicMenu;
        @BindView(R.id.tv_add_one)
        TextView mTvAddOne;
        @BindView(R.id.dynamic_reprint_time)
        TextView mDynamicTime;
        @BindView(R.id.dynamic_reprint_view_all)
        TextView mTvReprintViewAll;
        @BindView(R.id.dynamic_original_view_all)
        TextView mTvOriginalViewAll;
        @BindView(R.id.relay_item_recycler)
        RecyclerView commentRecyclerView;

        OtherHolder(View view) {
            super(view);
            mItem = view;
            ButterKnife.bind(this, view);
        }
    }

    public interface OnItemClickListener {

        void OnCommentClickListener(int position, PersonalDynamicBean.DataBean.NumberBean bean);

        void OnLikeClickListener(int position, boolean isLiked, View view, String aid, TextView addView);

        void OnReprintClickListener(int position, PersonalDynamicBean.DataBean.NumberBean bean);

        void OnMenuClickListener(int position, PersonalDynamicBean.DataBean.NumberBean bean);

        void OnRNameClickListener(int position, PersonalDynamicBean.DataBean.NumberBean bean);
    }

    public interface OnCenterMenuClickListener {

        void onFollowClick();

        void onAddFriendClick(boolean isFriend);

        void onChatClick(boolean isFriend, String photo);

        void onMoreClick(View view);
    }

    public interface OnAvatarClickListener{
        void onAvatarClick(String avatarPath);
    }

    public interface OnFansClickListener{
        void onFansClick(String uid, int currentTab);
    }

    private String getTime(String timeStamp) {
        long publishTime = Long.parseLong(timeStamp);
        long currentTime = new Date().getTime() / 1000;
        long timeDifference = currentTime - publishTime;
        long timeDifferenceHour = timeDifference / 3600;
        if (timeDifference / 60 < 1) {
            return "刚刚";
        } else if (timeDifferenceHour < 1) {
            return (timeDifference / 60) + "分钟前";
        } else if (timeDifferenceHour < 24) {
            return timeDifferenceHour + "小时前";
        } else if (timeDifferenceHour / 24 < 30) {
            return (timeDifferenceHour / 24) + "天前";
        } else {
            return DateUtil.getStrTime(timeStamp);
        }
    }
}
